﻿using SkladLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ToolBarLib
{
    /// <summary>
    /// Interaction logic for userToolBar.xaml
    /// </summary>
    public partial class userToolBar : UserControl
    {
        public delegate void ValueChangedEventHandler(object sender);
        public delegate void NovyZakaznikangedEventHandler(object sender , AddUserLib.NovaZakazkaEventArgs e);
        public event NovyZakaznikangedEventHandler AddedUser;
        public event ValueChangedEventHandler NewUser;

        public userToolBar()
        {
            InitializeComponent();
        }

        private void ToolBar_Loaded_1(object sender, RoutedEventArgs e)
        {
            
            ToolBar toolBar = sender as ToolBar;
            var overflowGrid = toolBar.Template.FindName("OverflowGrid", toolBar) as FrameworkElement;
            if (overflowGrid != null)
            {
                overflowGrid.Visibility = Visibility.Collapsed;
            }

            var mainPanelBorder = toolBar.Template.FindName("MainPanelBorder", toolBar) as FrameworkElement;
            if (mainPanelBorder != null)
            {
                mainPanelBorder.Margin = new Thickness(0);
            }
        }

        private void btnAddUser_Click_1(object sender, RoutedEventArgs e)
        {
            if (NewUser != null)
                NewUser(this);
            AddUserLib.AddUserWin addUserWin = new AddUserLib.AddUserWin();
            addUserWin.Show();
            addUserWin.NovaZakazka += addUserWin_NovaZakazka;
        }

        /// <summary>
        /// Event při přidání nového zákazníka
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void addUserWin_NovaZakazka(object sender, AddUserLib.NovaZakazkaEventArgs e)
        {
            e.SaveToDb(DataLib.Settings.databases.dbPujcky, "Nevracene");
            if (AddedUser != null)
                AddedUser(sender,e);
            Tisknout(e);
          
            //throw new NotImplementedException("Potřeba doplnit zapis do Databaze");
        }

        /// <summary>
        /// Vytiskne informace o zakaznikovi
        /// </summary>
        /// <param name="e"></param>
        private void Tisknout(AddUserLib.NovaZakazkaEventArgs e)
        {
            MicroStarPrinter.Printer.Print(e);   //Tisk
        }

        private void btnSklad_Click_1(object sender, RoutedEventArgs e)
        {
            SkladLib.SkladWin skladWin = new SkladLib.SkladWin();
            skladWin.Show();
        }

        private void btnStats_Click_1(object sender, RoutedEventArgs e)
        {
            Stats.Grafy grafy = new Stats.Grafy();
            if(grafy.IsInitialized)
                grafy.Show();   
        }

        private void btnRezervovat_Click_1(object sender, RoutedEventArgs e)
        {
            Rezervace.MainWindow rezervace = new Rezervace.MainWindow();
            rezervace.Show();
        }

        private void btnTiskarna_Click(object sender, RoutedEventArgs e)
        {
            /*
            PrinterStarMicronic.SettingsWin settingsWindow = new PrinterStarMicronic.SettingsWin();
            settingsWindow.Show();
             * */
        }
    }
}
